//
//  ViewController.m
//  RTUApp
//
//  Created by 陈德军 on 2017/5/18.
//  Copyright © 2017年 陈德军. All rights reserved.
//

#import "ViewController.h"
#import "UINavigationSubController.h"
#import "AutomaticPairVC.h"
#import "BasicParameterVC.h"
#import "PeriodOfTimeDataVC.h"
#import "RealTimeDataVC.h"

@interface ViewController (){
    
}
/**
 *  自定义Tabbar
 */
@property (nonatomic,strong) UITabBarController *tabBar;
/**
 *  基本参数控制器
 */
@property (nonatomic,strong) BasicParameterVC *basicParameterVC;
/**
 *  自动对时控制器
 */
@property (nonatomic,strong) AutomaticPairVC *automaticPairVC;
/**
 *  时段数据控制器
 */
@property (nonatomic,strong) PeriodOfTimeDataVC *periodOfTimeDataVC;
/**
 *  实时数据控制器
 */
@property (nonatomic,strong) RealTimeDataVC *realTimeDataVC;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self addTabBar:self.basicParameterVC title:@"基本参数" image:[UIImage imageNamed:@"ico1"] selecedImage:[UIImage imageNamed:@"ico1_1"] badgeValue:nil];
    
    [self addTabBar:self.automaticPairVC title:@"自动对时" image:[UIImage imageNamed:@"ico2"] selecedImage:[UIImage imageNamed:@"ico2_1"] badgeValue:nil];
    
    [self addTabBar:self.periodOfTimeDataVC title:@"时段数据" image:[UIImage imageNamed:@"ico3"] selecedImage:[UIImage imageNamed:@"ico3_1"] badgeValue:nil];
    
    [self addTabBar:self.realTimeDataVC title:@"实时数据" image:[UIImage imageNamed:@"ico4"] selecedImage:[UIImage imageNamed:@"ico4_1"] badgeValue:nil];
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:YES];
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:11.0f],
                                                        NSForegroundColorAttributeName : [UIColor colorWithRed:146/255.0 green:146/255.0 blue:145/255.0 alpha:1]
                                                        } forState:UIControlStateNormal];
    
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:11.0f],
                                                        NSForegroundColorAttributeName : KK_MailColor
                                                        } forState:UIControlStateSelected];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)addTabBar:(UIViewController *)viewController title:(NSString * )title image:(UIImage *)image selecedImage:(UIImage *)selecedImage badgeValue:(NSString *)value{
    
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    selecedImage = [selecedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //    viewController.tabBarItem.title=title;
    viewController.title=title;
    viewController.tabBarItem.image=image;
    
    viewController.tabBarItem.selectedImage=selecedImage;
    viewController.tabBarItem.badgeValue=value;
    
    UINavigationSubController * nav=[[UINavigationSubController alloc]initWithRootViewController:viewController];
    [self.tabBar addChildViewController:nav];
    [self.view addSubview:self.tabBar.view];
    
}


#pragma mark - 懒加载
- (UITabBarController *)tabBar{
    if (_tabBar==nil) {
        _tabBar =[[UITabBarController alloc]init];
    }
    return _tabBar;
}

- (BasicParameterVC *)basicParameterVC{
    if (_basicParameterVC==nil) {
        _basicParameterVC = [[BasicParameterVC alloc] init];
    }
    return _basicParameterVC;
}

- (AutomaticPairVC *)automaticPairVC{
    if (_automaticPairVC==nil) {
        _automaticPairVC = [[AutomaticPairVC alloc] init];
    }
    return _automaticPairVC;
}
- (PeriodOfTimeDataVC *)periodOfTimeDataVC{
    if (_periodOfTimeDataVC==nil) {
        _periodOfTimeDataVC = [[PeriodOfTimeDataVC alloc] init];
    }
    return _periodOfTimeDataVC;
}
- (RealTimeDataVC *)realTimeDataVC{
    if (_realTimeDataVC==nil) {
        _realTimeDataVC = [[RealTimeDataVC alloc] init];
    }
    return _realTimeDataVC;
}
@end
